package com.cdvtc.news.web.admin;

import com.cdvtc.news.entity.User;
import com.cdvtc.news.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping
    public String list(Model model) {
        List<User> userList = userService.getAllUsers();
        model.addAttribute("userList", userList);
        return "admin/user-list";
    }

    @RequestMapping("forbidden/{id}/{forbidden}")
    public String forbidden(@PathVariable Integer id, @PathVariable Boolean forbidden) {
        userService.forbiddenUser(id, forbidden);
        return "redirect:/admin/user";
    }
}
